home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 4 Database How-To / Visual Basic 4 Database - How-to (The Waite Group)(1995).iso / query3.fr_ / query3.fr
Text File  |  1995-07-05  |  5KB  |  156 lines

  1. VERSION 4.00
  2. Begin VB.Form Form1 
  3.    BackColor       =   &H00C0C0C0&
  4.    Caption         =   "Query Creator"
  5.    ClientHeight    =   3495
  6.    ClientLeft      =   435
  7.    ClientTop       =   1560
  8.    ClientWidth     =   7605
  9.    BeginProperty Font 
  10.       name            =   "MS Sans Serif"
  11.       charset         =   0
  12.       weight          =   700
  13.       size            =   8.25
  14.       underline       =   0   'False
  15.       italic          =   0   'False
  16.       strikethrough   =   0   'False
  17.    EndProperty
  18.    Height          =   3900
  19.    Left            =   375
  20.    LinkTopic       =   "Form1"
  21.    ScaleHeight     =   3495
  22.    ScaleWidth      =   7605
  23.    Top             =   1215
  24.    Width           =   7725
  25.    Begin VB.CommandButton cmdClose 
  26.       Cancel          =   -1  'True
  27.       Caption         =   "&Close"
  28.       Height          =   495
  29.       Left            =   4380
  30.       TabIndex        =   7
  31.       Top             =   2640
  32.       Width           =   1215
  33.    End
  34.    Begin VB.CommandButton cmdRefresh 
  35.       Caption         =   "&Refresh"
  36.       Default         =   -1  'True
  37.       Height          =   495
  38.       Left            =   2160
  39.       TabIndex        =   6
  40.       Top             =   2640
  41.       Width           =   1215
  42.    End
  43.    Begin VB.Frame grpSelection 
  44.       BackColor       =   &H00C0C0C0&
  45.       Caption         =   "Selection"
  46.       Height          =   1995
  47.       Left            =   5760
  48.       TabIndex        =   1
  49.       Top             =   240
  50.       Width           =   1515
  51.       Begin VB.OptionButton optPublisher 
  52.          BackColor       =   &H00C0C0C0&
  53.          Caption         =   "Publisher"
  54.          Height          =   255
  55.          Left            =   180
  56.          TabIndex        =   5
  57.          Top             =   1560
  58.          Width           =   1200
  59.       End
  60.       Begin VB.OptionButton optISBN 
  61.          BackColor       =   &H00C0C0C0&
  62.          Caption         =   "ISBN"
  63.          Height          =   255
  64.          Left            =   180
  65.          TabIndex        =   4
  66.          Top             =   1200
  67.          Width           =   1200
  68.       End
  69.       Begin VB.OptionButton optTitle 
  70.          BackColor       =   &H00C0C0C0&
  71.          Caption         =   "Title"
  72.          Height          =   315
  73.          Left            =   180
  74.          TabIndex        =   3
  75.          Top             =   780
  76.          Width           =   1200
  77.       End
  78.       Begin VB.OptionButton optAuthor 
  79.          BackColor       =   &H00C0C0C0&
  80.          Caption         =   "Author"
  81.          Height          =   255
  82.          Left            =   180
  83.          TabIndex        =   2
  84.          Top             =   420
  85.          Value           =   -1  'True
  86.          Width           =   1200
  87.       End
  88.    End
  89.    Begin VB.ListBox List1 
  90.       Height          =   1980
  91.       Left            =   360
  92.       Sorted          =   -1  'True
  93.       TabIndex        =   0
  94.       Top             =   300
  95.       Width           =   5175
  96.    End
  97. End
  98. Attribute VB_Name = "Form1"
  99. Attribute VB_Creatable = False
  100. Attribute VB_Exposed = False
  101. Option Explicit
  102. Const QUERY_NAME = "My Defined Query"
  103.  
  104. Private Sub cmdClose_Click()
  105.     End
  106. End Sub
  107.  
  108. Private Sub cmdRefresh_Click()
  109.     Dim db As DATABASE
  110.     Dim dbName As String
  111.     Dim qdNew As QueryDef, qdExists As QueryDef
  112.     Dim rs As Recordset
  113.     Dim sql As String
  114.     
  115.     On Error Resume Next
  116.     
  117.     Screen.MousePointer = 11
  118.     
  119.     ' Get the database name and open the database.
  120.     dbName = BiblioPath()       ' BiblioPath is a function in READINI.BAS
  121.     Set db = DBEngine.Workspaces(0).OpenDatabase(dbName)
  122.     
  123.     db.QueryDefs.DELETE QUERY_NAME
  124.     
  125.     If optAuthor Then
  126.         sql = "SELECT [Author] FROM [Authors]"
  127.     ElseIf optTitle Then
  128.         sql = "SELECT [Title] FROM [Titles]"
  129.     ElseIf optISBN Then
  130.         sql = "SELECT [ISBN] FROM [Titles]"
  131.     Else
  132.         sql = "SELECT [Name] FROM [Publishers]"
  133.     End If
  134.     Set qdNew = db.CreateQueryDef(QUERY_NAME, sql)
  135.     Set rs = qdNew.OpenRecordset()
  136.     qdNew.Close
  137.     If rs.RecordCount > 0 Then
  138.         FillList rs
  139.         Screen.MousePointer = 0
  140.     Else
  141.         List1.Clear
  142.         Screen.MousePointer = 0
  143.         MsgBox "The query returned no records", vbExclamation
  144.     End If
  145.             
  146. End Sub
  147. Sub FillList(rs As Recordset)
  148.     List1.Clear
  149.     rs.MoveFirst
  150.     Do
  151.         List1.AddItem rs.Fields(0)
  152.         rs.MoveNext
  153.     Loop While Not rs.EOF
  154.     
  155. End Sub
  156.